import logging
import os
import time
import sys
sys.path.append('../../')

class LogUtil:
    @classmethod
    def __init__(cls):
        try:
            os.mkdir('D:\\Log')
        except:
            pass

    @classmethod
    def Log(cls,text):
        # 打开文件
        f = open("D:\\Log\\Log.txt", "a")
        f.write(text)
        f.close()

    @classmethod
    def save_log(cls, logname, text):
        cls.__init__()
        today = time.strftime('%Y-%m-%d', time.localtime(time.time()))
        Log_time = time.strftime('%Y-%m-%d %H:%M:%S :', time.localtime(time.time()))
        # 打开文件
        f = open(f"D:\\Log\\{logname}-{today}.txt", "a")
        f.write(Log_time + '\n' + text + '\n\n')
        f.close()

    @classmethod
    def Log_tower(cls, text):
        today = time.strftime('%Y-%m-%d', time.localtime(time.time()))
        Log_time = time.strftime('%Y-%m-%d %H:%M:%S :', time.localtime(time.time()))
        # 打开文件
        f = open(f"D:\\Log\\Log_tower-{today}.txt", "a")
        f.write(Log_time + text + '\n\n')
        f.close()

    @classmethod
    def Log_wireless(cls, text):
        # text = text
        # logging.basicConfig(filename='E:\\Log_wireless.log', level=logging.DEBUG,format='%(asctime)s %(message)s')
        # logging.info(text)
        today = time.strftime('%Y-%m-%d', time.localtime(time.time()))
        Log_time = time.strftime('%Y-%m-%d %H:%M:%S :', time.localtime(time.time()))
        # 打开文件
        f = open(f"D:\\Log\\Log_wireless-{today}.txt", "a")
        f.write(Log_time + text)
        f.close()

    @classmethod
    def Log_all_business(cls, text):
        today = time.strftime('%Y-%m-%d', time.localtime(time.time()))
        Log_time = time.strftime('%Y-%m-%d %H:%M:%S :', time.localtime(time.time()))
        # 打开文件
        f = open(f"D:\\Log\\Log_allbusiness{today}.txt", "a")
        f.write(Log_time + text + '\n')
        f.close()

    @classmethod
    def Log_open_door(cls, text):
        today = time.strftime('%Y-%m-%d', time.localtime(time.time()))
        Log_time = time.strftime('%Y-%m-%d %H:%M:%S :', time.localtime(time.time()))
        # 打开文件
        f = open(f"D:\\Log\\Log_open_door-{today}.txt", "a")
        f.write(Log_time + text)
        f.close()

    @classmethod
    def Log_RT_Query(cls, text):
        cls.__init__()
        today = time.strftime('%Y-%m-%d', time.localtime(time.time()))
        Log_time = time.strftime('%Y-%m-%d %H:%M:%S :', time.localtime(time.time()))
        # 打开文件
        f = open(f"D:\\Log\\Log_RT_Query-{today}.txt", "a")
        f.write(text)
        f.close()

    @classmethod
    def Log_extraction(cls, text):
        today = time.strftime('%Y-%m-%d', time.localtime(time.time()))
        Log_time = time.strftime('%Y-%m-%d %H:%M:%S :', time.localtime(time.time()))
        # 打开文件
        f = open(f"D:\\Log\\Log_extraction-{today}.txt", "a")
        f.write(Log_time + text + '\n')
        f.close()


